$(function () {
    $("#waitcheck_datagrid").datagrid({
        fit: true,
        url: '/guaranteebill/queryBill?state=3',
        columns: [[
            {field: 'id', title: 'id', width: 10, hidden: true}, //hidden 隐藏显示该列
            {field: 'number', title: '保险单号', width: 10},//允许列改变大小
            {
                field: 'applicant', title: '投保人', width: 10,
                formatter: function (value, row, index) {
                    return value.name;
                }
            },
            {field: 'vdate', title: '申请日期', width: 10},
            {field: 'limityear', title: '保险时长', width: 10},
            {
                field: 'op', title: '业务员', width: 10,
                formatter: function (value, row, index) {
                    console.log(value)
                    return value.username;
                }
            },
            {field: 'totalprice', title: '投保总金额', width: 10}
        ]],
        rownumbers: true,
        striped: true,
        toolbar: "#waitcheck_toolbar",
        pagination: true,
        fitColumns: true,
        singleSelect: true
    })

    //高级查询
    $("#query").click(function () {
        var applicant = $("#applicant").textbox("getValue");
        var number = $("#number").textbox("getValue");
        $("#waitcheck_datagrid").datagrid("load", {
            applicant: applicant,
            number: number
        })
    })


    //刷新
    $("#reload").click(function () {
        $("#waitcheck_datagrid").datagrid("reload");
    })


    //退回修改
    $("#back").click(function () {
        var row = $("#waitcheck_datagrid").datagrid("getSelected");
        console.log(row);
        if (!row) {
            $.messager.alert("温馨提示", "至少选择一条数据");
        } else {
            var id = row.id;
            $.messager.prompt('确认','请输入批改意见？',function(r){
                if (r){
                    $.get("/guaranteebill/checkClientById", {id: id, message:r}, function (data) {
                        if (data) {
                            $("#waitcheck_datagrid").datagrid("reload");
                            $("#waitcheck_datagrid").datagrid("unselectAll");
                        } else {
                            $.messager.alert("退回修改操作", "操作失败", "error");
                        }
                    });
                }
            });
        }
    })


//审核通过
$("#auditSuccess").click(function () {
    var row = $("#waitcheck_datagrid").datagrid("getSelected");
    console.log(row);
    if (!row) {
        $.messager.alert("温馨提示", "至少选择一条数据");
    } else {
        var id = row.id;
        $.messager.confirm('核保', '您确认想要核审这条记录吗？', function (r) {
            $.get("/guaranteebill/auidSuccess", {id: id}, function (data) {
                if (data) {
                    $("#waitcheck_datagrid").datagrid("reload");
                    $("#waitcheck_datagrid").datagrid("unselectAll");
                } else {
                    $.messager.alert("核保操作", "操作失败", "error");
                }
            });
        })
    }
})

//拒保
$("#rejuest").click(function () {
    var row = $("#waitcheck_datagrid").datagrid("getSelected");
    console.log(row);
    if (!row) {
        $.messager.alert("温馨提示", "至少选择一条数据");
    } else {
        var id = row.id;
        $.messager.confirm('拒保', '您确认要拒保这个客户吗？', function (r) {
            if (r) {
                $.get("/guaranteebill/rejuest", {id: id}, function (data) {
                    if (data) {
                        $("#waitcheck_datagrid").datagrid("reload");
                        $("#waitcheck_datagrid").datagrid("unselectAll");
                    } else {
                        $.messager.alert("拒保保操作", "操作失败", "error");
                    }
                });
            }
        });
    }
})
    //查看投保人明细
    $("#client_dialog").dialog({
        title: '正式客户',
        width: 300,
        height: 300,
        buttons: "#sure",
        closed: "true"
    })

    //打开投保人的窗口
    $("#client").click(function () {
        var row = $("#waitcheck_datagrid").datagrid("getSelected");
        console.log(row);
        if (!row) {
            $.messager.alert("温馨提示", "至少选择一条数据");
        } else {
            var id = row.applicant.id;
            $("#client_form").form("load", "/latentClient/queryClientById?id=" + id);
            $("#client_dialog").dialog("open");
        }
    })

    /** ====================================保单查看弹出框=================================== */
    $("#showBill").click(function () {
        //编辑方法
        var row = $("#waitcheck_datagrid").datagrid("getSelected");
        if (!row) {
            $.messager.alert("温馨提示", '至少选择一条数据', 'warning');
            return;
        }
        console.log(row)
        var carId = row.carinfo.id;
        console.log(carId)
        $("#carinfo_form").form("load", "/guaranteebill/queryCarInfo?carId="+carId)
        $("#edit_dialog").dialog('open');
        $("#edit_dialog").dialog('center');

    });
    //初始化弹窗
    $("#edit_dialog").dialog({
        closed: true,
        title: '查看保单信息',
        width: 700,
        height: 600,
        buttons: '#showInfo_buttons',
        top: 200
    });

    //点击关闭事件
    $("#showInfo_cancel").click(function () {
        $("#show_dialog").dialog("close");
    });



})











